

/**************************************************************

	Script		: Text Resize Detector
	Version		: 1.1
	Authors		: Samuel birch
	Desc		: Captures when the text is resized.
	Licence		: Open Source MIT Licence

**************************************************************/

var textResizeDetector = new Class({
	getOptions: function(){
		return {
			delay: 200,
			_onChange: Class.empty
		};
	},
	
	initialize: function(options){
		this.setOptions(this.getOptions(), options);
		
		this.element = new Element('div').set({
			'id': 'textResizeController_'+$time(),
			'styles': {
				'position': 'absolute',
				'left': '-9999px',
				'top': 0,
				'width': '1em',
				'height': '20em'
			}
		}).inject(document.body);
		this.oldSize = this.element.getCoordinates().height;
		this.defaultSize = this.oldSize;
		//console.log(this.defaultSize/16); //20
		if(this.defaultSize/16 != 20){
			this.defaultSize = 20*16;
			this.options._onChange(this.defaultSize, this.oldSize);
		}
		this.start();
	},
	
	check: function(){
		var newSize = this.element.getCoordinates().height;
		if(this.oldSize != newSize){
			this.options._onChange(this.defaultSize, newSize, this.oldSize);
			this.oldSize = newSize;
		}
	},
	
	start: function(){
		this.timer = this.check.periodical(this.options.delay, this);
	},
	
	stop: function(){
		$clear(this.timer);
	}
});
textResizeDetector.implement(new Events);
textResizeDetector.implement(new Options);

/*************************************************************/
